import random
from src.config import config as cfg

print("this is Food.py")


# 食物类
# 方法： 放置/移除
# 点以25为单位
class Food:
    def __init__(self):
        self.pos = -1, -1

    def remove(self):
        self.pos = -1, -1

    def set(self, bricks):
        if self.pos == (-1, -1):
            all_pos_x = []
            all_pos_y = []
            # 不靠墙太近 25 ~ SCREEN_X-25 之间
            for pos in range(1, cfg.SCREEN_X // cfg.UNIT - 1):
                all_pos_x.append(pos)
            for pos in range(5, cfg.SCREEN_Y // cfg.UNIT - 1):
                all_pos_y.append(pos)

            while True:
                self.pos = random.choice(all_pos_x), random.choice(all_pos_y)
                if bricks[self.pos[1]][self.pos[0]] == 0:
                    print("ok")
                    return
                else:
                    print("same")
